package com.yanduo.tags

import org.apache.spark.sql.Row

/**
  * 关键字标签
 *
  * @author Gerry chan
  * 2020/5/5 22:03
  * @version 1.0
  */
object Tags4KeyWords extends Tags{
  override def makeTags(args: Any*): Map[String, Int] = {
    var map = Map[String, Int]()
    val row = args(0).asInstanceOf[Row]
    val stopWords = args(1).asInstanceOf[Map[String,Int]]
    val kws = row.getAs[String]("keywords")

    //kw先要删除空格
    kws.split("\\|").map(kw => kw.trim)
      .filter(kw=>kw.length>=3 && kw.length<=8 && !stopWords.contains(kws))
      .foreach(kw => map +="K"+kw->1)
    map
  }
}
